<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>老王登录</title>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<form id="loginForm">
    <label for="username">Username:</label>
    <input type="text" id="username" name="username" required />
    <label for="password">Password:</label>
    <input type="password" id="password" name="password" required />
    <button type="button" onclick="submitForm()">Login</button>
</form>
<script th:inline="javascript">
    function submitForm() {
        var username = $('#username').val();
        var password = $('#password').val();
        var user = {username: username, password: password};
        $.ajax({
            type: "POST",
            url: "/login/login",
            contentType: "application/json", // 指定发送的数据类型为JSON格式的字符串
            data: JSON.stringify(user), // 将JavaScript对象转换为JSON字符串作为请求体发送出去
            success: function(response) {
                alert(response); // 显示从服务器返回的响应信息
            },
            error: function(xhr, status, error) {
                alert("Error: " + error); // 显示错误信息，如请求失败的原因等。
        }});
    }
</script>
</body>
</html>